package com.joker.orange.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.joker.common.core.domain.PageQuery;
import com.joker.common.core.page.TableDataInfo;
import com.joker.orange.domain.CollectionInfo;
import com.joker.orange.domain.bo.CollectionBo;
import com.joker.orange.domain.vo.CollectionVo;
import com.joker.orange.mapper.CollectionMapper;
import com.joker.orange.service.ICollectionService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@RequiredArgsConstructor
@Service
public class CollectionServiceImpl implements ICollectionService {

    private final CollectionMapper collectionMapper;

    @Override
    public CollectionInfo selectCollection(CollectionInfo collectionInfo) {
        return collectionMapper.selectOne(new LambdaQueryWrapper<CollectionInfo>()
            .eq(CollectionInfo::getCollectionId,collectionInfo.getCollectionId())
            .eq(CollectionInfo::getUserId,collectionInfo.getUserId())
            .eq(CollectionInfo::getCollectionType,collectionInfo.getCollectionType()));
    }

    @Override
    public void deleteCollection(CollectionInfo collectionInfo) {
        collectionMapper.delete(new LambdaQueryWrapper<CollectionInfo>()
            .eq(CollectionInfo::getCollectionId,collectionInfo.getCollectionId())
            .eq(CollectionInfo::getUserId,collectionInfo.getUserId())
            .eq(CollectionInfo::getCollectionType,collectionInfo.getCollectionType()));
    }

    /**
     * 新增收藏
     */
    @Override
    public void insertCollection(CollectionInfo collectionInfo) {
        collectionMapper.insert(collectionInfo);
    }

    @Override
    public void deleteCollection(List<String> collectionIds) {
        collectionMapper.deleteBatchIds(collectionIds);
    }

    /**
     * 收藏By网格视频
     */
    @Override
    public TableDataInfo<CollectionVo> selectCollectionByLongVideo(CollectionBo bo) {
        PageQuery pageQuery = getPageQuery(bo);
        Page<CollectionVo> page = collectionMapper.selectCollectionByLongVideo(pageQuery.build(), bo);
        return TableDataInfo.build(page);
    }

    /**
     * 收藏By短视频
     */
    @Override
    public TableDataInfo<CollectionVo> selectCollectionByShortVideo(CollectionBo bo) {
        PageQuery pageQuery = getPageQuery(bo);
        Page<CollectionVo> page = collectionMapper.selectCollectionByShortVideo(pageQuery.build(), bo);
        return TableDataInfo.build(page);
    }

    /**
     * 收藏By小说
     */
    @Override
    public TableDataInfo<CollectionVo> selectCollectionByNovel(CollectionBo bo) {
        PageQuery pageQuery = getPageQuery(bo);
        Page<CollectionVo> page = collectionMapper.selectCollectionByNovel(pageQuery.build(), bo);
        return TableDataInfo.build(page);
    }

    /**
     * 收藏By动漫
     */
    @Override
    public TableDataInfo<CollectionVo> selectCollectionByAnime(CollectionBo bo) {
        PageQuery pageQuery = getPageQuery(bo);
        Page<CollectionVo> page = collectionMapper.selectCollectionByAnime(pageQuery.build(), bo);
        return TableDataInfo.build(page);
    }

    /**
     * 收藏By漫画
     */
    @Override
    public TableDataInfo<CollectionVo> selectCollectionByCaricature(CollectionBo bo) {
        PageQuery pageQuery = getPageQuery(bo);
        Page<CollectionVo> page = collectionMapper.selectCollectionByCaricature(pageQuery.build(), bo);
        return TableDataInfo.build(page);
    }

    private PageQuery getPageQuery(CollectionBo bo) {
        PageQuery pageQuery = new PageQuery();
        pageQuery.setPageNum(bo.getPageNum());
        pageQuery.setPageSize(bo.getPageSize());
        return pageQuery;
    }
}
